package com.iwhalecloud.bss.kite.cucc.order.accept.constructor;

import com.iwhalecloud.bss.kite.cucc.order.accept.constructor.inst.InstConstructor;
import com.iwhalecloud.bss.kite.cucc.order.accept.constructor.inst.RelConstructor;
import com.iwhalecloud.bss.kite.dataservice.entity.inst.IInst;
import com.iwhalecloud.bss.kite.manager.enums.InstType;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.graph.impl.RelEdge;
import com.ztesoft.bss.common.util.SpringUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * 数据构造器工厂
 */
public abstract class DataConstructorFactory {

    /**
     * 获取实例构造器
     * @param instType
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <I extends IInst, T extends IDataConstructor<String, I>> T getInstConstructor(InstType instType) {
        if (Objects.isNull(instType)) {
            return null;
        }

        Class<? extends InstConstructor<? extends KiteInst, ? extends IInst>> clazz = ConstructorTypeMap.getInstMap()
            .get(instType);
        return (T) SpringUtil.getBean(clazz);
    }

    /**
     * 获取关系构造器
     * @param relType
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <I extends IInst, T extends IDataConstructor<RelEdge, I>> T getRelConstructor(String relType) {
        if (StringUtils.isBlank(relType)) {
            return null;
        }

        Class<? extends RelConstructor<? extends IInst>> clazz = ConstructorTypeMap.getRelMap().get(relType);
        if (Objects.isNull(clazz)) {
            return null;
        }
        return (T) SpringUtil.getBean(clazz);
    }
}
